package com.banciyuan.bcywebview.biz.pc.zone.smooth;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.api.GroupApi;
import com.banciyuan.bcywebview.api.SpaceApi;
import com.banciyuan.bcywebview.base.helper.data.UserDataHelper;
import com.banciyuan.bcywebview.base.util.BaseObserver;
import com.banciyuan.bcywebview.base.view.foldview.FoldLayout;
import com.banciyuan.bcywebview.base.view.listview.NoScrollListView;
import com.banciyuan.bcywebview.base.view.recycleview.OnResultScrollListener;
import com.banciyuan.bcywebview.biz.groupdetail.NewTeamDetailActivity;
import com.banciyuan.bcywebview.biz.main.group.hot.GroupHotAdapterSearch;
import com.banciyuan.bcywebview.biz.main.mineinfo.mark.MarkCircleActivity;
import com.banciyuan.bcywebview.biz.pc.TeamsActivity;
import com.banciyuan.bcywebview.biz.pc.zone.BaseLazyScrollFragment;
import com.banciyuan.bcywebview.biz.write.photoselecotor.util.CommonUtils;
import com.banciyuan.bcywebview.utils.common.UIUtils;
import com.banciyuan.bcywebview.utils.http.BcyPair;
import com.banciyuan.bcywebview.utils.http.HttpUtils;
import com.banciyuan.bcywebview.utils.http.OnErrorProxy;
import com.banciyuan.bcywebview.utils.http.StatusCodeUtils;
import com.banciyuan.bcywebview.utils.http.StringRequestParam;
import com.banciyuan.bcywebview.utils.http.VolleyQueue;
import com.banciyuan.bcywebview.utils.intent.gotoUtil;
import com.banciyuan.bcywebview.utils.string.StringUtil;
import com.banciyuan.bcywebview.utils.universalimageloader.core.ImageLoader;
import com.banciyuan.bcywebview.utils.universalimageloader.utils.ImageOptions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import de.greenrobot.daoexample.model.AcgItem;
import de.greenrobot.daoexample.model.PersonAcgItem;
import de.greenrobot.daoexample.model.PersonTagDetail;
import de.greenrobot.daoexample.model.PreferWorkItem;
import de.greenrobot.daoexample.model.TagDetail;
import de.greenrobot.daoexample.model.Team;
import de.greenrobot.daoexample.model.UserDetail;

/**
 * Created by squall on 2015/11/3.
 */
public class SmoothPersonFragment extends BaseLazyScrollFragment implements View.OnClickListener, FoldLayout.FoldChild {

    private RequestQueue queue;
    private RecyclerView recyclerView;
    private PersonHolder personHolder;
    private FoldLayout.OnFoldScrollListener onFoldScrollListener;
    private LinearLayoutManager ll;

    private String uid;
    private UserDetail user;
    private List<Team> tlist = new ArrayList<>();

    private ImageLoader imageLoader;
    private boolean acg_flag = false;
    private boolean team_flag = false;
    private boolean tag_flag = false;
    private boolean perfer_flag = false;
    private int introDataEmpty = 0;
    private int acgDataEmpty = 0;
    private int tagDataEmpty = 0;
    private int topicDataEmpty = 0;
    private int preferDataEmpty = 0;
    private int min_height;

    private int offset;

    private PersonAdapter personAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View viewroot = inflater.inflate(R.layout.circle_smooth_fragment, null);
        initArgs();
        initUi(viewroot);
        initAction();
        return viewroot;
    }

    @Override
    public void fetchData() {
        BaseObserver.getInstance().notifyWatchers(BaseObserver.START_LOADING);
        setFlag();
        initData();
    }

    @Override
    protected void initArgs() {
        queue = VolleyQueue.getRquest(getActivity());
        imageLoader = ImageLoader.getInstance();
        uid = getArguments().getString("uid");
        min_height = CommonUtils.getHeightPixels(getActivity()) + UIUtils.dip2px(251, getActivity()) + getOffset();
    }

    private void setFlag() {
        acg_flag = false;
        team_flag = false;
        tag_flag = false;
        perfer_flag = false;
    }

    private void checkEnd() {
        try {
            if (acg_flag && team_flag && tag_flag && perfer_flag && !getActivity().isFinishing()) {
                if (personAdapter == null) {
                    personAdapter = new PersonAdapter();
                    recyclerView.setAdapter(personAdapter);
                } else {
                    personAdapter.notifyDataSetChanged();
                }
                BaseObserver.getInstance().notifyWatchers(BaseObserver.COMPELATE);
                personHolder.ll_about.setVisibility(View.VISIBLE);
                if (introDataEmpty == 1 && acgDataEmpty == 1 && tagDataEmpty == 1 && preferDataEmpty == 1 && topicDataEmpty == 1) {
                    personHolder.rl_empty.setVisibility(View.VISIBLE);
                    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, min_height);
                    personHolder.empty_blank.setLayoutParams(params);
                } else {
                    personHolder.rl_empty.setVisibility(View.GONE);
                    personHolder.ll_about.measure(
                            View.MeasureSpec.makeMeasureSpec(CommonUtils.getWidthPixels(getActivity()), View.MeasureSpec.AT_MOST),
                            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
                    if (personHolder.ll_about.getMeasuredHeight() < min_height) {
                        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, min_height - personHolder.ll_about.getMeasuredHeight());
                        personHolder.blank.setLayoutParams(params);
                    }
                }
                ll.scrollToPositionWithOffset(0, offset);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void initUi(View rootview) {
        personHolder = new PersonHolder(View.inflate(getActivity(), R.layout.smooth_person_fragment, null));

        recyclerView = (RecyclerView) rootview.findViewById(R.id.recycle);
        ll = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(ll);
        personAdapter = new PersonAdapter();
        recyclerView.setAdapter(personAdapter);

        SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) rootview.findViewById(R.id.swipe);
        swipeRefreshLayout.setEnabled(false);

        if (StringUtil.notNullEqual(uid, UserDataHelper.getInstance(getActivity()).getUid())) {
            personHolder.tvAcg.setText(getString(R.string.myorderacg));
            personHolder.tvTag.setText(getString(R.string.myordertag));
            personHolder.tvCos.setText(getString(R.string.mine_coser_work));
            personHolder.tvDrawer.setText(getString(R.string.mine_draw_work));
            personHolder.tvWriter.setText(getString(R.string.mine_write_work));
            personHolder.tvHisTeam.setText(getString(R.string.mine_topic));
        } else {
            personHolder.tvAcg.setText(getString(R.string.othersorderacg));
            personHolder.tvTag.setText(getString(R.string.other_order_tags));
            personHolder.tvCos.setText(getString(R.string.others_cos_work));
            personHolder.tvDrawer.setText(getString(R.string.others_draw_work));
            personHolder.tvWriter.setText(getString(R.string.others_write_work));
            personHolder.tvHisTeam.setText(getString(R.string.others_focus_topic));
        }
        personHolder.ll_about.setVisibility(View.GONE);
    }

    @Override
    protected void initAction() {
        recyclerView.addOnScrollListener(new OnResultScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (isVisibleToUser) {
                    LinearLayoutManager ll = (LinearLayoutManager) recyclerView.getLayoutManager();
                    if (dy < 0) {
                        if (ll.findFirstVisibleItemPosition() == 0 && ll.getChildAt(ll.findFirstVisibleItemPosition()).getTop() > -UIUtils.dip2px(202, getActivity())) {
                            onFoldScrollListener.onScroll(dy);
                        }
                    } else {
                        onFoldScrollListener.onScroll(dy);
                    }
                }
            }

            @Override
            public void onTop() {
                super.onTop();
                if (isVisibleToUser) {
                    showBottom(false);
                }
                onFoldScrollListener.onTop();
            }

            @Override
            public void onBottom() {
                super.onBottom();
                if (isVisibleToUser) {
                    showBottom(true);
                }
            }
        });

        personHolder.groupContainer.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                gotoUtil.gotoAct(getActivity(), NewTeamDetailActivity.class, tlist.get(position).getGid(), tlist.get(position).getName());
            }
        });

        personHolder.rlMoreTeam.setOnClickListener(this);
        personHolder.acg_line.setOnClickListener(this);
        personHolder.tag_line.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        getFocusedGroup();
        getPreferWork();
        getAcgInfo();
        getTagInfo();
    }

    private void getFocusedGroup() {
        List<BcyPair> paramsList = new ArrayList<BcyPair>();
        paramsList.add(new BcyPair(HttpUtils.TOKEN, UserDataHelper.getInstance(getActivity()).getToken()));
        paramsList.add(new BcyPair(HttpUtils.UID, uid));
        paramsList.add(new BcyPair(HttpUtils.INDEX_P, "1"));
        paramsList.add(new BcyPair(HttpUtils.LIMIT, "3"));

        final HashMap<String, String> params = HttpUtils.getData(paramsList);
        final String url = HttpUtils.BASE_URL + GroupApi.getFocusedgroup();

        Response.Listener onSuccess = new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                try {
                    if (StatusCodeUtils.dealStatusCode(s, getActivity())) {
                        JSONObject jsonObject = new JSONObject(s);
                        JSONArray result = jsonObject.getJSONArray("data");
                        Gson gson = new Gson();
                        List<Team> tlist = gson.fromJson(result.toString(), new TypeToken<List<Team>>() {
                        }.getType());
                        if (!tlist.isEmpty()) {
                            setWorkToTag(tlist);
                            renderGroup(tlist);
                        } else {
                            topicDataEmpty = 1;
                            personHolder.team_line.setVisibility(View.GONE);
                            team_flag = true;
                            checkEnd();
                        }
                    } else {
                        topicDataEmpty = 1;
                        personHolder.team_line.setVisibility(View.GONE);
                        team_flag = true;
                        checkEnd();
                    }
                } catch (Exception e) {
                    topicDataEmpty = 1;
                    personHolder.team_line.setVisibility(View.GONE);
                    team_flag = true;
                    checkEnd();
                }
            }
        };

        Response.ErrorListener onError = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                topicDataEmpty = 1;
                personHolder.team_line.setVisibility(View.GONE);
                team_flag = true;
                checkEnd();
            }
        };

        OnErrorProxy errorProxy = new OnErrorProxy(onError, onSuccess, url, getActivity(), params);
        StringRequestParam request = new StringRequestParam(Request.Method.POST, url, params, onSuccess, errorProxy);
        queue.add(request);
    }

    private void setWorkToTag(List<Team> templist) {
        for (Team h : templist) {
            if (!TextUtils.isEmpty(h.getWork())) {
                TagDetail tagDetail = new TagDetail();
                tagDetail.setWork(h.getWork());
                tagDetail.setWid(h.getId());
                tagDetail.setTag_name(h.getWork());
                h.getTags().add(0, tagDetail);
            }
        }
    }

    private void renderGroup(List<Team> templist) {
        tlist.clear();
        tlist.addAll(templist);
        personHolder.team_line.setVisibility(View.VISIBLE);
        GroupHotAdapterSearch groupHotAdapter = new GroupHotAdapterSearch(getActivity(), tlist);
        personHolder.groupContainer.setAdapter(groupHotAdapter);
        team_flag = true;
        topicDataEmpty = 0;
        checkEnd();
    }

    private void getPreferWork() {
        List<BcyPair> paramsList = new ArrayList<BcyPair>();
        paramsList.add(new BcyPair(HttpUtils.TOKEN, UserDataHelper.getInstance(getActivity()).getToken()));
        paramsList.add(new BcyPair(HttpUtils.UID, uid));
        final HashMap<String, String> params = HttpUtils.getData(paramsList);
        final String url = HttpUtils.BASE_URL + SpaceApi.getPreferwork();

        Response.Listener onSuccess = new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                try {
                    if (StatusCodeUtils.dealStatusCode(s, getActivity())) {
                        JSONObject jsonObject = new JSONObject(s);
                        JSONArray resultArray = jsonObject.getJSONArray("data");
                        processPreferData(resultArray);
                    } else {
                        preferDataEmpty = 1;
                        perfer_flag = true;
                        checkEnd();
                    }
                } catch (Exception e) {
                    preferDataEmpty = 1;
                    perfer_flag = true;
                    checkEnd();
                }
            }
        };

        Response.ErrorListener onError = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                preferDataEmpty = 1;
                perfer_flag = true;
                checkEnd();
            }
        };

        OnErrorProxy errorProxy = new OnErrorProxy(onError, onSuccess, url, getActivity(), params);
        StringRequestParam request = new StringRequestParam(Request.Method.POST, url, params, onSuccess, errorProxy);
        queue.add(request);
    }

    private void processPreferData(JSONArray resultArray) {
        personHolder.llCos.removeAllViews();
        personHolder.llDrawer.removeAllViews();
        personHolder.llWriter.removeAllViews();
        if (resultArray.length() != 0) {
            for (int i = 0; i < resultArray.length(); i++) {
                try {
                    JSONObject obj = (JSONObject) resultArray.get(i);
                    String data = obj.getString("data");
                    String type_name = obj.getString("type_name");
                    processPreferDataItem(type_name, data);
                } catch (Exception e) {
                    e.printStackTrace();
                    perfer_flag = true;
                    checkEnd();
                }
            }
        } else {
            preferDataEmpty = 1;
            perfer_flag = true;
            checkEnd();
        }
    }

    private void processPreferDataItem(String type_name, String data) {
        Gson gson = new Gson();
        List<PreferWorkItem> tempList = gson.fromJson(data, new TypeToken<List<PreferWorkItem>>() {
        }.getType());
        PreferWorkItem tempData;
        if (getString(R.string.coser_role).equals(type_name)) {
            if (!tempList.isEmpty()) {
                ((View) (personHolder.viewCos.getParent())).setVisibility(View.VISIBLE);
            }
            for (int i = 0; i < tempList.size(); i++) {
                tempData = tempList.get(i);
                View layout = View.inflate(getActivity(), R.layout.prefer_work_item, null);
                TextView tvPreferWorkName = (TextView) layout.findViewById(R.id.tv_preferwork_name);
                TextView tvPreferWorkDingNum = (TextView) layout.findViewById(R.id.tv_preferwork_dingnum);
                ImageView ivPreferWork = (ImageView) layout.findViewById(R.id.iv_preferwork);
                tvPreferWorkName.setText(tempData.getReal_name());
                tvPreferWorkDingNum.setText(tempData.getCount() + getString(R.string.charpter_unit));
                imageLoader.displayImage(tempData.getImg_src(), ivPreferWork, ImageOptions.options);
                personHolder.llCos.addView(layout);
            }
        }
        if (getString(R.string.draw_role).equals(type_name)) {
            if (!tempList.isEmpty()) {
                ((View) (personHolder.viewDrawer.getParent())).setVisibility(View.VISIBLE);
            }
            for (int i = 0; i < tempList.size(); i++) {
                tempData = tempList.get(i);
                View layout = View.inflate(getActivity(), R.layout.prefer_work_item, null);
                TextView tvPreferWorkName = (TextView) layout.findViewById(R.id.tv_preferwork_name);
                TextView tvPreferWorkDingNum = (TextView) layout.findViewById(R.id.tv_preferwork_dingnum);
                ImageView ivPreferWork = (ImageView) layout.findViewById(R.id.iv_preferwork);
                tvPreferWorkName.setText(tempData.getReal_name());
                tvPreferWorkDingNum.setText(tempData.getCount() + getString(R.string.charpter_unit));
                imageLoader.displayImage(tempData.getImg_src(), ivPreferWork, ImageOptions.options);
                personHolder.llDrawer.addView(layout);
            }
        }
        if (getString(R.string.write_role).equals(type_name)) {
            if (!tempList.isEmpty()) {
                ((View) (personHolder.viewWriter.getParent())).setVisibility(View.VISIBLE);
            }
            for (int i = 0; i < tempList.size(); i++) {
                tempData = tempList.get(i);
                View layout = View.inflate(getActivity(), R.layout.prefer_work_item, null);
                TextView tvPreferWorkName = (TextView) layout.findViewById(R.id.tv_preferwork_name);
                TextView tvPreferWorkDingNum = (TextView) layout.findViewById(R.id.tv_preferwork_dingnum);
                ImageView ivPreferWork = (ImageView) layout.findViewById(R.id.iv_preferwork);
                tvPreferWorkName.setText(tempData.getReal_name());
                tvPreferWorkDingNum.setText(tempData.getCount() + getString(R.string.charpter_unit));
                imageLoader.displayImage(tempData.getImg_src(), ivPreferWork, ImageOptions.options);
                personHolder.llWriter.addView(layout);
            }
        }
        preferDataEmpty = 0;
        perfer_flag = true;
        checkEnd();
    }

    private void getAcgInfo() {
        List<BcyPair> paramsList = new ArrayList<BcyPair>();
        paramsList.add(new BcyPair(HttpUtils.TOKEN, UserDataHelper.getInstance(getActivity()).getToken()));
        paramsList.add(new BcyPair(HttpUtils.UID, uid));
        final HashMap<String, String> params = HttpUtils.getData(paramsList);
        String url = HttpUtils.BASE_URL + SpaceApi.getSubScribedCores();

        Response.Listener onSuccess = new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                try {
                    if (StatusCodeUtils.dealStatusCode(s, getActivity())) {
                        JSONObject jsonObject = new JSONObject(s);
                        JSONObject result = jsonObject.getJSONObject("data");
                        Gson gson = new Gson();
                        PersonAcgItem personAcgItem = gson.fromJson(result.toString(), PersonAcgItem.class);
                        if (!personAcgItem.getCore_data().isEmpty()) {
                            personHolder.acg_line.setVisibility(View.VISIBLE);
                            renderAcgInfo(personAcgItem);
                        } else {
                            acgDataEmpty = 1;
                            personHolder.acg_line.setVisibility(View.GONE);
                            acg_flag = true;
                            checkEnd();
                        }
                    } else {
                        acgDataEmpty = 1;
                        personHolder.acg_line.setVisibility(View.GONE);
                        acg_flag = true;
                        checkEnd();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    acgDataEmpty = 1;
                    personHolder.acg_line.setVisibility(View.GONE);
                    acg_flag = true;
                    checkEnd();
                }
            }
        };

        Response.ErrorListener onError = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                acgDataEmpty = 1;
                personHolder.acg_line.setVisibility(View.GONE);
                acg_flag = true;
                checkEnd();
            }
        };

        OnErrorProxy errorProxy = new OnErrorProxy(onError, onSuccess, url, getActivity(), params);
        StringRequestParam stringRequest = new StringRequestParam(Request.Method.POST, url, params, onSuccess, errorProxy);
        queue.add(stringRequest);
    }

    private void renderAcgInfo(PersonAcgItem personAcgItem) {
        personHolder.ll_acg.removeAllViews();
        personHolder.tvAcgNum.setText(personAcgItem.getFollow_count());
        for (int i = 0; i < 5; i++) {
            View view = View.inflate(getActivity(), R.layout.person_focus_item, null);
            ImageView iv = (ImageView) view.findViewById(R.id.header);
            TextView same_tv = (TextView) view.findViewById(R.id.same_focus);
            TextView title = (TextView) view.findViewById(R.id.title);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            params.setMargins(UIUtils.dip2px(8, getActivity()), 0, UIUtils.dip2px(8, getActivity()), 0);
            params.weight = 1;
            view.setLayoutParams(params);
            if (i < personAcgItem.getCore_data().size()) {
                AcgItem a = personAcgItem.getCore_data().get(i);
                view.setVisibility(View.VISIBLE);
                ImageLoader.getInstance().displayImage(a.getImg_src(), iv, ImageOptions.options);
                if (!TextUtils.isEmpty(a.getReal_name())) {
                    title.setText(a.getReal_name());
                }
                if (a.is_common()) {
                    same_tv.setVisibility(View.VISIBLE);
                } else {
                    same_tv.setVisibility(View.GONE);
                }
            } else {
                view.setVisibility(View.INVISIBLE);
            }
            personHolder.ll_acg.addView(view);
        }
        acgDataEmpty = 0;
        acg_flag = true;
        checkEnd();
    }

    private void getTagInfo() {
        List<BcyPair> paramsList = new ArrayList<>();
        paramsList.add(new BcyPair(HttpUtils.TOKEN, UserDataHelper.getInstance(getActivity()).getToken()));
        paramsList.add(new BcyPair(HttpUtils.UID, uid));
        final HashMap<String, String> params = HttpUtils.getData(paramsList);
        String url = HttpUtils.BASE_URL + SpaceApi.getSubScribedTags();

        Response.Listener onSuccess = new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                try {
                    if (StatusCodeUtils.dealStatusCode(s, getActivity())) {
                        JSONObject jsonObject = new JSONObject(s);
                        JSONObject result = jsonObject.getJSONObject("data");
                        Gson gson = new Gson();
                        PersonTagDetail personTagDetail = gson.fromJson(result.toString(), PersonTagDetail.class);
                        if (!personTagDetail.getTag_data().isEmpty()) {
                            tagDataEmpty = 1;
                            personHolder.tag_line.setVisibility(View.VISIBLE);
                            renderTaginfo(personTagDetail);
                        } else {
                            tagDataEmpty = 1;
                            personHolder.tag_line.setVisibility(View.GONE);
                            tag_flag = true;
                            checkEnd();
                        }
                    } else {
                        tagDataEmpty = 1;
                        personHolder.tag_line.setVisibility(View.GONE);
                        tag_flag = true;
                        checkEnd();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    tagDataEmpty = 1;
                    personHolder.tag_line.setVisibility(View.GONE);
                    tag_flag = true;
                    checkEnd();
                }
            }
        };

        Response.ErrorListener onError = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                tagDataEmpty = 1;
                personHolder.tag_line.setVisibility(View.GONE);
                tag_flag = true;
                checkEnd();
            }
        };

        OnErrorProxy errorProxy = new OnErrorProxy(onError, onSuccess, url, getActivity(), params);
        StringRequestParam stringRequest = new StringRequestParam(Request.Method.POST, url, params, onSuccess, errorProxy);
        queue.add(stringRequest);
    }

    private void renderTaginfo(PersonTagDetail personTagDetail) {
        personHolder.ll_tag.removeAllViews();
        personHolder.tvTagNum.setText(personTagDetail.getFollow_count());
        for (int i = 0; i < 5; i++) {
            View view = View.inflate(getActivity(), R.layout.person_focus_item, null);
            ImageView iv = (ImageView) view.findViewById(R.id.header);
            TextView title = (TextView) view.findViewById(R.id.title);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            params.setMargins(UIUtils.dip2px(8, getActivity()), 0, UIUtils.dip2px(8, getActivity()), 0);
            params.weight = 1;
            view.setLayoutParams(params);
            if (i < personTagDetail.getTag_data().size()) {
                view.setVisibility(View.VISIBLE);
                TagDetail t = personTagDetail.getTag_data().get(i);
                view.setVisibility(View.VISIBLE);
                ImageLoader.getInstance().displayImage(t.getCover(), iv, ImageOptions.options);
                if (!TextUtils.isEmpty(t.getTag_name())) {
                    title.setText(t.getTag_name());
                }
            } else {
                view.setVisibility(View.INVISIBLE);
            }
            personHolder.ll_tag.addView(view);
        }
        tagDataEmpty = 0;
        tag_flag = true;
        checkEnd();
    }

    public void setSelf(UserDetail user) {
        this.user = user;
        boolean flag1 = false;
        boolean flag2 = false;
        if (user != null) {
            if (user.isValue_user()) {
                personHolder.llVip.setVisibility(View.VISIBLE);
                personHolder.vipTv.setText(user.getVerify_info());
            } else {
                personHolder.llVip.setVisibility(View.GONE);
            }
            if (TextUtils.isEmpty(user.getSelf_intro())) {
                personHolder.tvHeadIntro.setText(getString(R.string.lazy));
                flag1 = true;
            } else {
                introDataEmpty = 0;
                personHolder.tvHeadIntro.setText(Html.fromHtml(user.getSelf_intro()));
            }
            if (TextUtils.isEmpty(user.getLocation())) {
                personHolder.tvHeadAddress.setText(getString(R.string.unkonw_address));
                flag2 = true;
            } else {
                introDataEmpty = 0;
                personHolder.tvHeadAddress.setText(user.getLocation());
            }
            personHolder.tvTeamTotalNum.setText(String.valueOf(user.getGroup_num()));
            if (flag1 && flag2) {
                introDataEmpty = 1;
            }
        }
    }

    private void showBottom(boolean flag) {
        if (flag) {
            BaseObserver.getInstance().notifyWatchers(BaseObserver.SHOW_BOTTOM);
        } else {
            BaseObserver.getInstance().notifyWatchers(BaseObserver.HIDE_BOTTOM);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_more_team:
                Intent intent = new Intent(getActivity(), TeamsActivity.class);
                intent.putExtra("uid", uid);
                intent.putExtra("groupNum", user == null ? "0" : String.valueOf(user.getGroup_num()));
                startActivity(intent);
                break;
            case R.id.acg_line:
                intent = new Intent(getActivity(), MarkCircleActivity.class);
                intent.putExtra(gotoUtil.INTENT_VALUE_ONE, MarkCircleActivity.TYPE_WORK);
                intent.putExtra(gotoUtil.INTENT_VALUE_TWO, uid);
                startActivity(intent);
                break;
            case R.id.tag_line:
                intent = new Intent(getActivity(), MarkCircleActivity.class);
                intent.putExtra(gotoUtil.INTENT_VALUE_ONE, MarkCircleActivity.TYPE_TAG);
                intent.putExtra(gotoUtil.INTENT_VALUE_TWO, uid);
                startActivity(intent);
                break;

        }
    }

    @Override
    public void getParentHeight(int height) {
        if (!isVisibleToUser) {
            LinearLayoutManager ll = (LinearLayoutManager) recyclerView.getLayoutManager();
            int index = ll.findFirstVisibleItemPosition();
            if (index == 0 || index == -1) {
                offset = height;
                ll.scrollToPositionWithOffset(0, height);
            }
        }
    }

    @Override
    public void passParentScrollY(FoldLayout.OnFoldScrollListener onFoldScrollListener) {
        this.onFoldScrollListener = onFoldScrollListener;
    }


    private class PersonHolder extends RecyclerView.ViewHolder {

        private TextView tvHeadIntro;
        private TextView tvHeadAddress;
        private TextView tvTeamTotalNum;
        private RelativeLayout rlMoreTeam;
        private ImageView ivMoreTeamGo;
        private TextView tvAcg;
        private TextView tvAcgNum;
        private TextView tvTag;
        private TextView tvTagNum;
        private NoScrollListView groupContainer;
        private LinearLayout llCos;
        private LinearLayout llDrawer;
        private LinearLayout llWriter;
        private LinearLayout llVip;
        private View viewCos;
        private View viewDrawer;
        private View viewWriter;
        private TextView tvCos;
        private TextView tvDrawer;
        private TextView tvWriter;
        private TextView vipTv;
        private LinearLayout self_line;
        private LinearLayout acg_line;
        private LinearLayout tag_line;
        private LinearLayout team_line;
        private LinearLayout ll_about;
        private LinearLayout ll_acg;
        private LinearLayout ll_tag;
        private View blank;
        private View empty_blank;
        private RelativeLayout rl_empty;
        private TextView tvHisTeam;

        public PersonHolder(View itemView) {
            super(itemView);

            rl_empty = (RelativeLayout) itemView.findViewById(R.id.rl_about_emptyview);
            blank = itemView.findViewById(R.id.bottom_blank);
            empty_blank = itemView.findViewById(R.id.empty_bottom_blank);

            ll_about = (LinearLayout) itemView.findViewById(R.id.ll_about);
            self_line = (LinearLayout) itemView.findViewById(R.id.self_line);
            acg_line = (LinearLayout) itemView.findViewById(R.id.acg_line);
            tag_line = (LinearLayout) itemView.findViewById(R.id.tag_line);
            team_line = (LinearLayout) itemView.findViewById(R.id.team_line);

            tvAcgNum = (TextView) itemView.findViewById(R.id.tv_acg_num);
            tvTag = (TextView) itemView.findViewById(R.id.tv_tag);
            tvTagNum = (TextView) itemView.findViewById(R.id.tv_tag_num);

            tvHeadIntro = (TextView) itemView.findViewById(R.id.tv_head_intro);
            tvHeadAddress = (TextView) itemView.findViewById(R.id.tv_head_address);
            tvTeamTotalNum = (TextView) itemView.findViewById(R.id.tv_moreteam_num);
            rlMoreTeam = (RelativeLayout) itemView.findViewById(R.id.rl_more_team);
            ivMoreTeamGo = (ImageView) itemView.findViewById(R.id.iv_moreteam_go);

            tvAcg = (TextView) itemView.findViewById(R.id.tv_acg);
            groupContainer = (NoScrollListView) itemView.findViewById(R.id.ll_group_container);

            llCos = (LinearLayout) itemView.findViewById(R.id.ll_cos);
            llDrawer = (LinearLayout) itemView.findViewById(R.id.ll_drawer);
            llWriter = (LinearLayout) itemView.findViewById(R.id.ll_writer);
            llVip = (LinearLayout) itemView.findViewById(R.id.ll_vip);
            ll_acg = (LinearLayout) itemView.findViewById(R.id.ll_acg);
            ll_tag = (LinearLayout) itemView.findViewById(R.id.ll_tag);

            vipTv = (TextView) itemView.findViewById(R.id.tv_head_vip);
            viewCos = itemView.findViewById(R.id.view_cos);
            viewDrawer = itemView.findViewById(R.id.view_drawer);
            viewWriter = itemView.findViewById(R.id.view_writer);

            tvCos = (TextView) itemView.findViewById(R.id.tv_cos);
            tvDrawer = (TextView) itemView.findViewById(R.id.tv_drawer);
            tvWriter = (TextView) itemView.findViewById(R.id.tv_writer);
            tvHisTeam = (TextView) itemView.findViewById(R.id.tv_his_team);
        }
    }

    private class PersonAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return personHolder;
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        }

        @Override
        public int getItemCount() {
            return 1;
        }
    }


}